package com.dd.ljzapplication.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;

import com.dd.ljzapplication.R;
import com.dd.ljzapplication.fragment.lazy.LFragmentFour;
import com.dd.ljzapplication.fragment.lazy.LFragmentOne;
import com.dd.ljzapplication.fragment.lazy.LFragmentThree;
import com.dd.ljzapplication.fragment.lazy.LFragmentTwo;

import java.util.ArrayList;
import java.util.List;

import base.BaseUtilActivity;
import butterknife.ButterKnife;
import butterknife.InjectView;

import static android.R.attr.visibility;
import static com.baidu.location.h.j.v;

/**
 * Created by LiJZ on 2016/11/29.
 */

public class LazyLoadActivity extends BaseUtilActivity {
	@InjectView(R.id.vp)
	ViewPager vp;
	private ArrayList<Fragment> mListDate;


	@Override
	protected int setLayoutID() {
		return R.layout.activity_lazy_load;
	}

	@Override
	protected void init() {
		ButterKnife.inject(this);
	}

	@Override
	protected void initActionBar() {

	}

	@Override
	protected void initView() {
		LFragmentOne one = new LFragmentOne();
		LFragmentTwo two = new LFragmentTwo();
		LFragmentThree three = new LFragmentThree();
		LFragmentFour four = new LFragmentFour();

		mListDate = new ArrayList<>();
		mListDate.add(one);
		mListDate.add(two);
		mListDate.add(three);
		mListDate.add(four);

		FragmentManager supportFragmentManager = getSupportFragmentManager();
		MyAdapter mAdapter = new MyAdapter(supportFragmentManager);
		List<Fragment> fragments = supportFragmentManager.getFragments();
		vp.setAdapter(mAdapter);
	}

	@Override
	protected void initEvent() {
		vp.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
			@Override
			public void onSystemUiVisibilityChange(int visibility) {
				Log.e("@@@", "onSystemUiVisibilityChange--------> visibility:" + visibility);
			}
		});

		vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
			@Override
			public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
				Log.e("@@@", "onPageScrolled-------->position：" + position + ",positionOffset" + positionOffset + ",positionOffsetPixels" + positionOffsetPixels);
				if (position == 0) {

				} else if (position == 1) {

				} else if (position == 2) {

				} else if (position == 3) {

				}
			}

			@Override
			public void onPageSelected(int position) {
				Log.e("@@@", "onPageSelected-------> " + "position:" + position);
			}

			@Override
			public void onPageScrollStateChanged(int state) {
				Log.e("@@@", "onPageScrollStateChanged-------> " + "state:" + state);
			}
		});


	}

	private class MyAdapter extends FragmentPagerAdapter {

		public MyAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			return mListDate.get(position);
		}

		@Override
		public int getCount() {
			return mListDate.size();
		}
	}

}
